import numpy as np

from config import SCORE_MAP, CH_TO_EN_MAP


class Coefficient:

    @classmethod
    def get_ach_coefficient(cls, line):
        """
        获取ach系数的方法
        :param line: 证据行数
        :return:
        """
        res = np.random.normal(size=(1, line))
        return res


    @classmethod
    def ACH_to_score(cls, evidence_list):
        """
        将证据ACH转成相应分数
        :param evidence_list: 证据集合 [{}, {}....]
        :return:
        """
        res = []
        for evidence in evidence_list:
            sorce_list = []
            credibility = CH_TO_EN_MAP[evidence["credibility"]]
            relevance = CH_TO_EN_MAP[evidence["relevance"]]
            for i in evidence["ACH"]:
                sorce = 0
                if i not in ["I", "II"]:
                    sorce_list.append(sorce)
                else:
                    sorce = SCORE_MAP[(credibility, relevance)][i]
                    sorce_list.append(sorce)
            res.append(sorce_list)
        return np.array(res)

    @classmethod
    def calculation_socre(cls, ach_score, ach_coefficient):
        return np.dot(ach_coefficient, ach_score)
